<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="${pageContext.request.contextPath }/js/kindeditor-4.1.10/themes/default/default.css" type="text/css" rel="stylesheet">
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath }/js/kindeditor-4.1.10/kindeditor-all-min.js"></script>
<script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath }/js/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<link id="easyuiTheme" rel="stylesheet" type="text/css"	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/default.css">
<script type="text/javascript" src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"	type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/js/outOfBounds.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath }/js/common.js" type="text/javascript"></script>

<!-- 导入ztree类库 -->
<link rel="stylesheet" href="${pageContext.request.contextPath }/js/ztree/zTreeStyle.css" type="text/css" />
<script	src="${pageContext.request.contextPath }/js/ztree/jquery.ztree.all-3.5.js" type="text/javascript"></script>	

</head>

<body>
	<table class="easyui-datagrid" id="userList" title="用户列表" 
       data-options="singleSelect:false,collapsible:true,pagination:true,url:'${pageContext.request.contextPath}/admin/userlist',method:'get',pageSize:30,toolbar:toolbar">
    <thead>
        <tr>
        	<th data-options="field:'ck',checkbox:true"></th>
        	<th data-options="field:'id',width:120,align:'center'">编号</th>
            <th data-options="field:'username',width:100,align:'center'">用户名</th>
            <th data-options="field:'gender',width:50,align:'center',formatter:function(val,rec){
            	if(val == '1'){
            		return '男';
            	} if(val == '0') {
            		return '女';
            	}
            	return '未知';
            }">性别</th>
            <th data-options="field:'realname',width:100,align:'center'">真实姓名</th>
            <th data-options="field:'company',width:200,align:'center'">公司</th>
            <th data-options="field:'department',width:100,align:'center'">部门</th>
            <th data-options="field:'position',width:100,align:'center'">职位</th>
            <th data-options="field:'telephone',width:100,align:'center'">电话</th>
            <th data-options="field:'status',width:100,align:'center',formatter:HONGXIN.formatStatus">是否可用</th>
        </tr>
    </thead>
</table>
</body>
<div id="userAddWindow" class="easyui-window" title="添加用户" data-options="modal:true,closed:true,iconCls:'icon-save',href:'${pageContext.request.contextPath }/admin/user_add'" style="width:1000px;height:500px;padding:10px;">
<div id="userEditWindow" class="easyui-window" title="编辑用户" data-options="modal:true,closed:true,iconCls:'icon-save',href:'${pageContext.request.contextPath }/admin/user_edit'" style="width:1000px;height:500px;padding:10px;">
</div>
<script>
	//获取选中的ID值
    function getSelectionsIds(){
    	var userList = $("#userList");
    	var sels = userList.datagrid("getSelections");
    	var ids = [];
    	for(var i in sels){
    		ids.push(sels[i].id);
    	}
    	ids = ids.join(",");
    	return ids;
    }
	
	//删除功能
	function doDelete(){
		//获取选中的id
		var ids = getSelectionsIds();
		
		$.messager.confirm('确认','确定删除ID为 '+ids+' 的用户吗？',function(r){
    	    if (r){
    	    	var params = {"ids":ids};
            	$.post("${pageContext.request.contextPath }/admin/userdelete",params, function(data){
        			if(data.status == 200){
        				 $.messager.alert('提示', data.data, 'info', function() {
 							$("#userList").datagrid("reload");
 					});
        			}
        		});
    	    }
    	});
		
	}
	
	//添加功能
	function doAdd(){
		//打开弹窗
		$("#userAddWindow").window( ).window("open");		
	}
	
	//锁定用户
	function doLock(){
		
		//获取选中的id
		var ids = getSelectionsIds();
		$.messager.confirm('确认','确定锁定ID为 '+ids+' 的用户吗？',function(r){
    	    if (r){
    	    	var params = {"ids":ids};
            	$.post("${pageContext.request.contextPath }/admin/userlock",params, function(data){
        			if(data.status == 200){
        				 $.messager.alert('提示', data.data, 'info', function() {
 							$("#userList").datagrid("reload");
 					});
        			}
        		});
    	    }
    	});
		
	}
	
	//解锁用户
	function doUnlock(){
		//获取选中的id
		var ids = getSelectionsIds();
		$.messager.confirm('确认','确定解锁ID为 '+ids+' 的用户吗？',function(r){
    	    if (r){
    	    	var params = {"ids":ids};
            	$.post("${pageContext.request.contextPath }/admin/userunlock",params, function(data){
        			if(data.status == 200){
        				 $.messager.alert('提示', data.data, 'info', function() {
 							$("#userList").datagrid("reload");
 					});
        			}
        		});
    	    }
    	});
		
	}
	
	//编辑功能
	function doEdit(){
		var ids = getSelectionsIds();

    	if(ids.length == 0){
    		$.messager.alert('提示','必须选择一个用户才能编辑!');
    		return ;
    	}
    	if(ids.indexOf(',') > 0){
    		$.messager.alert('提示','只能选择一个用户!');
    		return ;
    	}
    	
    	$("#userEditWindow").window({
    		onLoad :function(){
    			//回显基础数据
    			//获取选中行的数据
    			var data = $("#userList").datagrid("getSelected");
    			
    			$("#userEditForm").form("load",data);
    		}
    	}
   		).window("open");
    	
	}

    var toolbar = [{
        text:'添加用户',
        iconCls:'icon-add',
        handler:doAdd
    },{
        text:'编辑用户',
        iconCls:'icon-edit',
        handler: doEdit
    },{
        text:'锁定用户',
        iconCls:'icon-no',
        handler: doLock
    },{
        text:'解锁用户',
        iconCls:'icon-remove',
        handler: doUnlock
    },{
        text:'删除用户',
        iconCls:'icon-cancel',
        handler: doDelete
    }];
    
</script>